package com.swt.gap.controller;

import com.swt.gap.model.vo.RelationshipAndPropertyVO;
import com.swt.gap.model.vo.RelationshipCountPropertyVO;
import com.swt.gap.service.OntologyRelationshipService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 请填写说明
 *
 * @author sx
 * @date 2020/6/17 18:20
 */
@Api(tags = "本体关系，即图谱配置中关系、边部分")
@RestController
@RequestMapping("/ontology/relationship")
@Slf4j
public class OntologyRelationshipController {

    private final OntologyRelationshipService ontologyRelationshipService;

    public OntologyRelationshipController (OntologyRelationshipService ontologyRelationshipService) {
        this.ontologyRelationshipService = ontologyRelationshipService;
    }

    @GetMapping("/relationship-property")
    @ApiOperation(value = "根据节点ids获取关系以及属性", notes = "根据节点ids获取关系以及属性")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startNodeLabelId", dataType = "int",paramType = "query", value = "文档节点的labels"),
            @ApiImplicitParam(name = "endNodeLabelId", dataType = "int",paramType = "query", value = "对方节点的labels")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = RelationshipAndPropertyVO.class, responseContainer = "List")
    })
    public ResponseEntity<List<RelationshipAndPropertyVO>> getEntityRelationshipVO(@RequestParam Integer startNodeLabelId,
                                                                                   @RequestParam Integer endNodeLabelId){
        return ResponseEntity.ok(ontologyRelationshipService.listRelationshipsByStartIdAndEndId(startNodeLabelId, endNodeLabelId));
    }

    @GetMapping("/count-property")
    @ApiOperation(value = "获取指定任务下可统计的边的属性", notes = "获取指定任务下可统计的边的属性")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", dataType = "int",paramType = "query", value = "任务Id")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = RelationshipCountPropertyVO.class, responseContainer = "List")
    })
    public ResponseEntity<List<RelationshipCountPropertyVO>> listCountPropertyByTaskId(@RequestParam Integer taskId) {
        return ResponseEntity.ok(ontologyRelationshipService.listCountPropertyByTaskId(taskId));
    }
}
